package com.kpx.app.wigdet;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;

import com.kpx.app.R;
import com.kpx.app.base.ActivityBase;
import com.kpx.app.bean.GrowthChildBean;
import com.kpx.app.bean.GrowthChildBean2;
import com.kpx.app.bean.HelpBean;
import com.kpx.app.http.HttpDataApi;
import com.kpx.app.http.HttpDataLoader;
import com.kpx.app.http.HttpDataReqUrl;
import com.kpx.app.http.HttpDataRequest;
import com.kpx.app.http.ResObj;
import com.kpx.app.utils.MyHashMap;
import com.kpx.app.utils.uiutils.ToastUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by congdy on 17/4/22.
 */

public class ViewShowGrowth extends LinearLayout {
    @BindView(R.id.ll_container)
    LinearLayout llContainer;

    public ViewShowGrowth(Context context, HelpBean.ChildsBean growthBean) {
        super(context);
        View view = View.inflate(context, R.layout.view_show_growth, this);
        ButterKnife.bind(view);
        getShow(growthBean, context);
    }

    private void getShow(HelpBean.ChildsBean growthBean, final Context context) {
        ((ActivityBase) context).showLoadingDialog();
        MyHashMap map = new MyHashMap();
        map.put("parentId", growthBean.getDmId() + "");
        new HttpDataLoader(new HttpDataApi.OnRequestCallback() {
            @Override
            public void onRequestSuccess(String url, ResObj result, boolean isFrmCache) {
                ((ActivityBase) context).dissmissLoadingDialog();
                if (result.getCode() == 0) {
                    ArrayList<GrowthChildBean2> gclist = (ArrayList<GrowthChildBean2>) result.getData();
                    if (gclist != null && gclist.size() > 0) {
                        for (int i = 0; i < gclist.size(); i++) {
                            ViewShowGrowthChild child = new ViewShowGrowthChild(context, gclist.get(i));
                            llContainer.addView(child);
                        }
                    }

                } else {
//                    ToastUtil.getInstance().showToast(context, result.getMsg());
                }
            }

            @Override
            public void onRequestError(String url, int statusCode, String error) {
                ((ActivityBase) context).dissmissLoadingDialog();
                ToastUtil.getInstance().showToast(context, error);
            }

        }, GrowthChildBean2.class, HttpDataRequest.TYPE_LIST).POST(HttpDataReqUrl.URL_POST_GET_GROWTH_FENLEI_C2, true, map);
    }
}
